package controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @date 2025/9/25
 */
public class HelloController implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        ModelAndView mav = new ModelAndView();
        //存储数据
        //该方式相当于向request作用域中存储数据
        //即:request.setAttribute(bute,value)
        mav.addObject("msg","Hello SpringMVC");
        //设置视图名，用于页面跳转
        //视图名需要经过viewResolver解析的
        //最终访问的页面为:前缀+视图名+后缀
        //例如:此处前缀配置为:/WEB-INF/pages/,后缀配置为:.jsp
        //那么最终访问的页面即为:/WEB-INF/pages/hello.jsp
        mav.setViewName("hello");
        return mav;
    }
}
